﻿/// <reference path="../../../Views/Product/NodeConfiguration.cshtml" />
window.SearchKey = null;
$.MGJ.ProductBatch = [];
(function () {
    var _this = $.MGJ.ProductBatch;
    $.extend($.MGJ.ProductBatch, {
        Execl: function (ele) {

            $("input.AllClickChild:checked").each(function () {
                info.push($(this).attr('ID'));

            });
            if (info.length == 0) {
                $.L.msgError("请选择要导出的数据信息！");
                return
            }
            if (!$(ele).find('.no-result').hasClass('no-result')) {
                window.open(ACTION_URL("ExportExecl", "Product") + "?Key=" + info);
            }
            else {
                $.L.msgWarning('导出数据不能为空！')
            }
            
        }
    });
})(jQuery);


(function () {
    var _index = 1;
    var _this = $.MGJ.ProductBatch;
    $.extend($.MGJ.ProductBatch, {
        // 新增产品批次
        Dialog_AddBatchObj: null,
        Dialog_AddBatch: function () {
            this.Dialog_AddBatchObj = $.L.dialog({
                url: ACTION_URL("AddBatch", "Product"),
                title: "新增产品批次",
                width: 800,
                height: 'auto',
                buttons: {
                    "button_save": {
                        type: 'primary',
                        text: '保存',
                        click: function () {
                            var bootstrapValidator = $("#Product_form").data('bootstrapValidator');
                            bootstrapValidator.validate();
                            if (bootstrapValidator.isValid()) {
                                $.MGJ.ProductBatch.Ajax_AddBatch();
                                $(".btn-primary").attr("disabled", true);
                            }
                            else {
                                $.L.msgError("请检查数据格式！");
                            };
                        }
                    },
                    "button_cancel": {
                        type: 'default',
                        text: '取消',
                        click: 'MODALMISS'
                    }
                }
            });
        },
        Dialog_EditBatchObj: null,
        Dialog_EditBatch: function (obj) {
            var id = $(obj).attr("PID");
            this.Dialog_EditBatchObj = $.L.dialog({
                url: ACTION_URL("EditBatch", "Product") + "?id=" + id,
                title: "编辑",
                width: 800,
                height: "auto",
                buttons: {
                    "button_save": {
                        type: 'primary',
                        text: '保存',
                        click: function () {
                            var bootstrapValidator = $("#Product_Editform").data('bootstrapValidator');
                            bootstrapValidator.validate();
                            if (bootstrapValidator.isValid()) {
                                $.MGJ.ProductBatch.Ajax_editProductBatch();
                                $(".btn-primary").attr("disabled", true);
                            }
                            else {
                                $.L.msgError("请检查数据格式！");
                            };
                         
                        }
                    },
                    "button_cancel": {
                        type: 'default',
                        text: '取消',
                        click: 'MODALMISS'
                    }
                }
            });
        },
        Ajax_ProductBatchList: function (pageIndex) {
            _index = pageIndex;
            window.SearchKey = removeSpace($("#BatchName").val());
            $.L.ajaxHandle({
                url: ACTION_URL("ProductBatchList", "Product") + "?pageindex=" + pageIndex,
                data: $("#SearchForm").serialize(),
                success: function (response) {
                    $("#ProductBatchTable").L_bindingDataList(response);

                }
            });
        },   //添加
        Ajax_AddBatch: function () {

            var data = $("#Product_form").serialize();
            $.L.ajaxHandle({
                url: ACTION_URL("AddProductBatch", "Product"),
                data: data,
                type: 'POST',
                success: function (response) {
                    if (response > 0) {
                        _this.Ajax_ProductBatchList(1);
                        _this.Dialog_AddBatchObj.close();
                        $.L.msgSuccess("操作成功！");
                    }
                    else {
                        $.L.msgSuccess("操作失败！");
                    }
                }
            });
        },
        //修改
        Ajax_editProductBatch: function (obj) {
  
            if ($("#Remark").val() == "") {
                $("#Remark").val(" ") ;
            }

            var id = $(obj).attr("PID");
            $.L.ajaxHandle({
                url: ACTION_URL("UpdBatch", "Product") + "?id=" + id,
                data: $("#Product_Editform").serialize(),
                success: function (response) {
                    if (response > 0) {
                        _this.Dialog_EditBatchObj.close();
                        $.L.msgSuccess("操作成功！");
                        _this.Ajax_ProductBatchList(1);
                    }
                }
            });
        },
        //删除
        Ajax_DelBatch: function (obj) {
            $.L.msgConfirm("确认删除该记录?", function () {
                var id = $(obj).attr("PID");
                $.L.ajaxHandle({
                    url: ACTION_URL("DelBatchList", "Product") + "?id=" + id,
                    data: { id: id },
                    success: function (response) {
                        if (response > 0) {
                            $.L.msgSuccess("操作成功！");
                            _this.Ajax_ProductBatchList(_index);

                        }
                    }
                });
            })
        },
    });
})(jQuery);


(function () {
    var _this = $.MGJ.ProductBatch;
    $.extend($.MGJ.ProductBatch, {
        ChangeModel: function (_this) {
            if (_this.value == "iphone7") {
                $("#iphoneViews").css("width","375px")
            } else {
                $("#iphoneViews").css("width", "414px")
            }
        },
        _H5Edit: function (obj) {
            RootsPathAndID(obj)
            var materialId = $(obj).attr("materialId");
            var batchId = $(obj).attr("batchId");
            $.MGJ.Common.loadurl(this, '/OriginsMaterial/EditOriginsMaterial?materialId=' + materialId+"&batchId="+batchId);
        }
    });
})(jQuery);









